package com.jy.datapipeline.importserver.service.strategy.executor;

import com.jy.datapipeline.common.constants.ExpConstants;
import com.jy.datapipeline.common.exception.GlobalException;
import com.jy.datapipeline.common.util.BeanFactoryUtil;
import com.jy.datapipeline.importserver.common.enums.impl.ImportModeEnum;
import com.jy.datapipeline.importserver.entity.ImportRule;
import com.jy.datapipeline.importserver.service.ImportModeService;
import com.jy.datapipeline.importserver.service.impl.JdbcImportModeServiceImpl;
import com.jy.datapipeline.importserver.service.impl.SqddlrImportModeServiceImpl;
import com.jy.datapipeline.importserver.service.strategy.ImportModeServiceStrategy;

/**
 * @类名 ImportModeExecurator
 * @描述 TODO
 * @作者 白条君
 * @创建日期 2023/9/1 16:17
 * @版本 1.0
 */
public class ImportModeExecutor {

    //根据策略执行导入方式
    public static void execute(ImportRule importRule) {
        String importMode = importRule.getImportMode();
        ImportModeService importModeService;
        if (String.valueOf(ImportModeEnum.SQLLDR_TOOL_MODE.getCode()).equals(importMode)) {
            importModeService = BeanFactoryUtil.getBean(SqddlrImportModeServiceImpl.class);
        } else if (String.valueOf(ImportModeEnum.JDBC_PROTOCOL_MODE.getCode()).equals(importMode)) {
            importModeService = BeanFactoryUtil.getBean(JdbcImportModeServiceImpl.class);
        } else {
            throw new GlobalException(ExpConstants.IMPORT_MODE_EXP);
        }
        BeanFactoryUtil
                .getBean(ImportModeServiceStrategy.class)
                .setImportModeService(importModeService)
                .loadMode(importRule);
    }
}
